﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using Domain;
using Microsoft.AspNet.SignalR;
using SilverlightRest.Web.SignalR;

namespace SilverlightRest.Web.Controllers
{

    public class PersonController : ApiController
    {

        private readonly ISomeRepository _someRepository;

        public PersonController(ISomeRepository someRepository)
        {
            _someRepository = someRepository;
        }

        [ActionName("DoEcho")]
        [HttpPost]
        public string DoEcho([FromBody] string input)
        {
            return input;
        }

        [ActionName("SayHello")]
        [HttpPost]
        public string SayHello()
        {
            return "Hello!";
        }
       
        [ActionName("UpdatePerson")]
        [HttpPost]
        public Person UpdatePerson(Person p)
        {

            var person = new Person { Name = "morten" };
            var workPlace = new WorkPlace { WorkPlaceName = "Miracle A/S", Person = person };
            person.WorkPlace = workPlace;
            person.Tasks = new Dictionary<int, Task>();
            person.Tasks.Add(new KeyValuePair<int, Task>(123, new Task { TaskName = "my task" }));

            GlobalHost.ConnectionManager.GetHubContext<MyHub>().Clients.All.hello(string.Format("Person: {0} was updated", p.Name));

//            oid SendMessage(string message)
//{
//   GlobalHost
//  .ConnectionManager
//  .GetHubContext<NotificationHub>().Clients.sendMessage(
//message);
//}

            return person;
        }
     
    }
}
